package com.epapyrus.plugpdf;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;

import com.epapyrus.plugpdf.core.annotation.menu.item.ColorItem;
import com.epapyrus.plugpdf.core.annotation.tool.AnnotSetting;

import static android.R.attr.button;
import static com.epapyrus.plugpdf.core.gesture.BaseGestureProcessor.GestureType.VIEW;

/**
 * Created by jeongjunsix on 8/18/17.
 */
class ColorPickerAdapter extends BaseAdapter {

    private Context context;
    private int[] color = new int[10];
    LayoutInflater inflater;


    public ColorPickerAdapter(Context context, int[] colorSet) {
        this.context = context;
        color = colorSet;
        inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.grid_item, null);
        }

        ImageView imageView = (ImageView) convertView.findViewById(R.id.grid_item);
        if(position == 0) {
            imageView.setBackgroundColor(AnnotSetting.instance().getColorPickerLineColor());
        } else {
            imageView.setBackgroundColor(color[position] + 0xff000000);
        }
        return convertView;
    }

    @Override
    public int getCount() {
        return color.length;
    }

    @Override
    public Object getItem(int position) {
        if (position == 0) return AnnotSetting.instance().getColorPickerLineColor();
        return color[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

}